package com.atgion.manager.service.impl.client;

import com.atgion.manager.mapper.CategoryMapper;
import com.atgion.manager.service.client.CategoryService;
import com.atgion.spzx.model.bo.blog.CategoryDO;
import com.atgion.spzx.model.vo.base.Result;
import com.atgion.spzx.model.vo.blog.client.QueryCategoryListItemRspVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: 犬小哈
 * @url: www.quanxiaoha.com
 * @date: 2023-04-17 12:08
 * @description: TODO
 **/
@Service
@Slf4j
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, CategoryDO> implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Result queryCategoryList() {
        List<CategoryDO> categoryDOList = categoryMapper.selectList(null);
        List<QueryCategoryListItemRspVO> list = null;
        if (!CollectionUtils.isEmpty(categoryDOList)) {
            list = categoryDOList.stream()
                    .map(p -> QueryCategoryListItemRspVO.builder()
                            .id(p.getId())
                            .name(p.getName())
                            .build())
                    .collect(Collectors.toList());
        }
        return Result.success(list);
    }


}
